// pages/purchaser-home/purchaser-home.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    topFilter: '1067246875800000066',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getList(){
    app.reqFetch.getOrder({
      canteenid: this.data.topFilter
    }, (res) => {

      const{list}=res
      this.setData({list})
    })
  },
  toDetails(e){
    const { status, mealTime, canteenId, supplierId, batchOrderId } = e.currentTarget.dataset.record
    if (status===0){
      wx.navigateTo({
        url: '/pages/purchaser-apply/purchaser-apply?data=' + JSON.stringify({ status, mealTime, canteenId, batchOrderId, supplierId})
      })
    }else{
      wx.navigateTo({
        url: '/pages/purchaser-apply-details/purchaser-apply-details?data=' + JSON.stringify({ canteenId, supplierId, batchOrderId}),
      })
    }


  
  },
  onChange(event) {
    if (event.detail === 1) {
      wx.redirectTo({
        url: '/pages/mine/mine',
      })
    }
  },
  changeFilter(e) {
    const { type } = e.currentTarget.dataset
    this.setData({ topFilter: type }, () => {
      this.getList()
    })
  },
})